package com.helios.user.service;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.helios.user.bean.ManagerLog;
import com.helios.user.mapper.ManagerLogMapper;

@Service
public class ManagerLogService {
	
	private Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private ManagerLogMapper managerLogMapper;
	
	public List<ManagerLog> gets(Integer id, Integer page, Integer rows) {
		try {
			int index = (page - 1) * rows;
            if (index < 0) index = 0;
			return managerLogMapper.gets(id, index, rows);
		} catch (Exception e) {
			logger.error(String.format("获取[管理员操作日志]异常,异常原因:%s", e.getMessage()));
			return null;
		}
	}
	
	public Integer getCount(Integer id) {
		try {
			return managerLogMapper.getCount(id);
		} catch (Exception e) {
			logger.error(String.format("获取[管理员操作日志个数]异常,异常原因:%s", e.getMessage()));
			return 0;
		}
	}
	
	public boolean save(Integer managerId, String todo, Integer result) {
		ManagerLog log = new ManagerLog();
		log.setMid(managerId);
		log.setTodo(todo);
		log.setResult(result);
		log.setTime(new Date());
		return save(log);
	}
	
	public boolean save(ManagerLog bean) {
		try {
			return managerLogMapper.insert(bean) == 1;
		} catch (Exception e) {
			logger.error(String.format("保存[管理员操作日志]异常,异常原因:%s", e.getMessage()));
			return false;
		}
	}
}
